import {createRouter, createWebHashHistory} from 'vue-router';

const routes = [
    {name: 'notFound', path: '/:path(.*)+', redirect: {name: 'goods'}},
    {name: 'user', path: '/user', component: () => import('@/views/user'), meta: {title: '会员中心'}},
    {name: 'cart', path: '/cart', component: () => import('@/views/cart'), meta: {title: '购物车'}},
    {name: 'goods', path: '/goods', component: () => import('@/views/goods'), meta: {title: '商品详情'}},
    {name: 'index', path: '/index', component: () => import('@/views/index'), meta: {title: 'index'}},
    {name: 'im', path: '/im', component: () => import('@/views/im'), meta: {title: '环信'}},
];

const router = createRouter({
    routes,
    history: createWebHashHistory(),
});

router.beforeEach((to, from, next) => {
    const title = to.meta && to.meta.title;
    if (title) {
        document.title = title;
    }
    next();
});

export {router};
